//
//  MentionViewController.m
//  DaDaBao
//
//  Created by user on 15/8/20.
//  Copyright (c) 2015年 User. All rights reserved.
//
#import "CardManageModel.h"
#import "MentionViewController.h"
#import "SuccessViewController.h"

@interface MentionViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>
@property (nonatomic,strong) UITableView * mainTableView;
@property (nonatomic,strong) UITextField * mentionMoneyTextfield;//提现金额
@property (nonatomic,strong) UIButton    * verifiCodeBtn;
@property (nonatomic,strong) UITextField * verifiCodeTextfield;
@property (nonatomic,strong) NSMutableArray * bankArray;
@property (nonatomic, assign) int             idx;
@property (nonatomic,assign) int           statusInt;//计数-倒计时
@property (nonatomic, strong) NSString  *availableBalance;
@property (nonatomic,strong) NSTimer     * timer;
@property (nonatomic,strong) UILabel     * tipLabel;//提示
@property (nonatomic, assign) NSInteger selectedCard;
@property (nonatomic,strong)NSMutableDictionary * selectDict;//用来解决按钮重用问题
@property (nonatomic,assign)int n;

@end

@implementation MentionViewController

- (id)initWithAvailableBalance:(NSString *)availableBalance
{
    self = [super init];
    if(self)
    {
        _availableBalance = availableBalance;
    }
    return self;
}

-(void)dealloc
{
    [self.timer invalidate];
    self.timer = nil;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    

}
//时间倒计时
-(void)timeCounting
{
    NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
    if ([phoneVersion doubleValue] > 8.0) {
        [_verifiCodeBtn setTitle:[NSString stringWithFormat:@"%d秒后重试",_statusInt] forState:UIControlStateNormal];
    }
    else{
        _verifiCodeBtn.titleLabel.frame =CGRectMake(0, 0, _verifiCodeBtn.frame.size.width, _verifiCodeBtn.frame.size.height);
        _verifiCodeBtn.titleLabel.text = [NSString stringWithFormat:@"%d秒后重试",_statusInt] ;
    }
    
    if(_statusInt == 0)
    {
        
        if ([phoneVersion doubleValue] > 8.0)
        {
            [_verifiCodeBtn setTitle:@" 重新获取 " forState:UIControlStateNormal];
        }
        else
        {
            _verifiCodeBtn.titleLabel.frame =CGRectMake(0, 0, _verifiCodeBtn.frame.size.width, _verifiCodeBtn.frame.size.height);
            _verifiCodeBtn.titleLabel.text = @" 重新获取 " ;
        }

        _statusInt = 60;
        _verifiCodeBtn.enabled = TRUE;
        [_verifiCodeBtn setTitleColor:[UIColor hexStringToColor:RED_COLOR_VALUE] forState:UIControlStateNormal];
        _verifiCodeBtn.layer.borderColor = [[UIColor hexStringToColor:RED_COLOR_VALUE]CGColor];
        [_timer invalidate];
        _timer = nil;
        return;//直接返回
    }
    _statusInt -=1;
}
- (void)getHttpData
{
    //重置选择字典
    [_selectDict removeAllObjects];
    _selectedCard = 0;
    _n++;
    [MBProgressHUD showHUDAddedTo:self.view animated:TRUE];
    
    NSDictionary *dict = @{ @"page.size":[NSNumber numberWithInt:10],@"page.pn":[NSNumber numberWithInt:_idx + 1], @"token":[[NSUserDefaults standardUserDefaults]objectForKey:@"token"] };
    [AppGlobalClass PostDataWithNSstring:BIND_CARD_LIST_URL withDictionary:dict success:^(NSDictionary *dictionary){
        if([[dictionary objectForKey:@"success"] isEqualToNumber:[NSNumber numberWithBool:TRUE]])
        {
            [_mainTableView.header endRefreshing];
            [_mainTableView.footer setState:MJRefreshStateIdle];
            
            [_mainTableView.footer endRefreshing];
            

            if(_idx == 0)
            {
                [_bankArray removeAllObjects];
            }
            
            NSArray *dataArray = [dictionary objectForKey:@"responseData"];
            NSDictionary *dataDict = [dataArray objectAtIndex:0];
            
            if([[dataDict objectForKey:@"pages"] intValue] > _idx)
            {
               
                NSMutableArray *listArray = [[[dictionary objectForKey:@"responseData"]firstObject] objectForKey:@"rows"];
                
                for(int i = 0; i < listArray.count; i++)
                {
                    CardManageModel *cardManageModel = [[CardManageModel alloc]initWithDictionary:[listArray objectAtIndex:i]];
                    [_bankArray addObject:cardManageModel];
                }
                
                _idx++;
                 [_mainTableView reloadData];
                
                if(listArray.count < 10)
                {
                    [_mainTableView.footer noticeNoMoreData];
                }
                else
                {
                    if (_n<2) {
                        _mainTableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(AddtoTheProjectTableView)];
                        
                    }

                }
            }
            else
            {
                if (self.bankArray.count==0) {
                    NSString * message = [NSString stringWithFormat:@"%@\n%@",@"您未绑定银行卡，无法提现！",@"请先去账户设置-->银行卡管理进行设置"];
                    
                    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    alertView.tag = 101;
                    [alertView show];
                }
                
                [self.mainTableView.footer noticeNoMoreData];
            }
        }
        [MBProgressHUD hideHUDForView:self.view animated:TRUE];

    } failure:^(NSError *error){
        [_mainTableView.header endRefreshing];
        [_mainTableView.footer setState:MJRefreshStateIdle];
        
        [_mainTableView.footer endRefreshing];

        [MBProgressHUD hideHUDForView:self.view animated:TRUE];
    } networkerror:^(NSString *networkerror){
        [_mainTableView.header endRefreshing];
        [_mainTableView.footer setState:MJRefreshStateIdle];
        
        [_mainTableView.footer endRefreshing];

        [self.bankArray removeAllObjects];
        [self.mainTableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:TRUE];
    }];
}
#pragma mark alertDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 99)
    {
        [AppGlobalClass exitLogin];
        LoginViewController *loginViewCon = [[LoginViewController alloc]init];
        [self presentViewController:loginViewCon animated:TRUE completion:^{}];
        
        NSArray *listArray = self.navigationController.viewControllers;
        
        id tabBar = [listArray objectAtIndex:1];
        if([[tabBar class] isSubclassOfClass:[UITabBarController class]])
        {
            UITabBarController *tabBarCon = tabBar;
            tabBarCon.selectedIndex = 0;
            [self.navigationController popToViewController:[listArray objectAtIndex:1] animated:TRUE];
        }
        else
        {
            UITabBarController *tabBarCon = [listArray objectAtIndex:2];
            tabBarCon.selectedIndex = 0;
            [self.navigationController popToViewController:[listArray objectAtIndex:2] animated:TRUE];
        }
    }
    if(alertView.tag == 100)
    {
        if(buttonIndex == 1)
        {
            [MBProgressHUD showHUDAddedTo:self.view animated:TRUE];
            
            CardManageModel *cardManagerModel = [_bankArray objectAtIndex:_selectedCard - 1];
            UITextField *textField = [alertView textFieldAtIndex:0];
            NSDictionary *dict = @{ @"token" : [[NSUserDefaults standardUserDefaults]objectForKey:@"token"], @"applyAmount":_mentionMoneyTextfield.text, @"userCardId":cardManagerModel.userCardId, @"mobileNumber":[[NSUserDefaults standardUserDefaults]objectForKey:@"mobile"], @"checkCode":_verifiCodeTextfield.text, @"payPassword":textField.text };
            [AppGlobalClass PostDataWithNSstring:MENTION_MONEY_URL withDictionary:dict success:^(NSDictionary *dictionary){
                if([[dictionary objectForKey:@"success"] isEqualToNumber:[NSNumber numberWithBool:TRUE]])
                {
                    SuccessViewController *successViewCon =[[SuccessViewController alloc]initWithTitle:@"申请提现成功" andTips:@"申请已提交，具体到账时间以银行为准"];
                    [self.navigationController pushViewController:successViewCon animated:TRUE];
                }
                else
                {
                    ALERT_VIEW([dictionary objectForKey:@"message"]);
                }
                    [MBProgressHUD hideAllHUDsForView:self.view animated:TRUE];
                } failure:^(NSError *error){
                        [MBProgressHUD hideAllHUDsForView:self.view animated:TRUE];
                } networkerror:^(NSString *networkerror){
                        [MBProgressHUD hideAllHUDsForView:self.view animated:TRUE];
                }];

                    
              
            
        }
    }
    
    if (alertView.tag == 101)
    {
        [self.navigationController popViewControllerAnimated:TRUE];
    }
}

-(void)reloginView
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"登录失败，请重新登录" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert setTag:99];
    [alert show];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:TRUE];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloginView) name:@"reLogin" object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter]removeObserver:self];
     [MBProgressHUD hideAllHUDsForView:self.view animated:TRUE];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor hexStringToColor:@"#ebebeb"];
    _selectDict = [[NSMutableDictionary alloc]initWithCapacity:0];
    _statusInt = 60;
    _selectedCard = 0;
    [self createTheNavigationBar];
    _bankArray=[[NSMutableArray alloc]initWithCapacity:0];
    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64 + 10, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 20) style:UITableViewStylePlain];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _mainTableView.backgroundColor = [UIColor hexStringToColor:@"#ebebeb"];
    [self.view addSubview:_mainTableView];
    

    
    __weak __typeof(self) weakSelf = self;
    
    // 设置回调（一旦进入刷新状态就会调用这个refreshingBlock）
    _mainTableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf refreshTheProjectTableView];
    }];
    

    // 马上进入刷新状态
    [_mainTableView.header beginRefreshing];
    
    [self creatTheFooterView];//创建footerView
    
    //开启键盘通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
}
#pragma mark ------------创建导航栏
-(void)createTheNavigationBar
{
    [[UIApplication sharedApplication]setStatusBarHidden:FALSE];
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
    
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 64.0f)];
    topView.backgroundColor = [UIColor hexStringToColor:COLOR_VALUE];
    [self.view addSubview:topView];
    //标题
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0.0f, 20.0f, SCREEN_WIDTH, 44.0f)];
    titleLab.backgroundColor = [UIColor clearColor];
    titleLab.font = [UIFont boldSystemFontOfSize:20.0f];
    titleLab.textColor = [UIColor whiteColor];
    titleLab.text = @"提现";
    titleLab.textAlignment = NSTextAlignmentCenter;
    [topView addSubview:titleLab];
    
    //返回按钮
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0.0f, 20.0f, 64.0f, 44.0f)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(buttonBackTapped:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:backBtn];
    
}
#pragma mark-----------键盘通知方法
- (void)keyboardWillShow:(NSNotification *)notification {
    
    NSDictionary *userInfo = [notification userInfo];
    
    // Get the origin of the keyboard when it's displayed.
    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    
    CGRect keyboardRect = [aValue CGRectValue];
    keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
    
    CGFloat keyboardTop = keyboardRect.origin.y;
    CGRect newTextViewFrame = self.view.bounds;
    newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y ;
    // Get the duration of the animation.
    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration;
    [animationDurationValue getValue:&animationDuration];
    
    // Animate the resize of the text view's frame in sync with the keyboard's appearance.
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:animationDuration];
    self.mainTableView.frame = CGRectMake(0, 64+10, SCREEN_WIDTH, newTextViewFrame.size.height-64-10);
    [UIView commitAnimations];
}

- (void)keyboardWillHide:(NSNotification *)notification {
    
    NSDictionary* userInfo = [notification userInfo];
    
    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration;
    [animationDurationValue getValue:&animationDuration];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:animationDuration];
    
    self.mainTableView.frame = CGRectMake(0, 64 + 10, SCREEN_WIDTH, SCREEN_HEIGHT- 64 - 10);
    [UIView commitAnimations];
}


#pragma mark--------创建表尾
-(void)creatTheFooterView
{
    UIView * backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 280)];
    _mainTableView.tableFooterView = backView;
    
    UIView * chargeView = [[UIView alloc]initWithFrame:CGRectMake(0,10, SCREEN_WIDTH, 50)];
    chargeView.backgroundColor = [UIColor whiteColor];
    [backView addSubview:chargeView];
    
    UILabel * chargeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, 50)];
    chargeLabel.text = @"提现金额";
    chargeLabel.textColor = [UIColor blackColor];
    [chargeView addSubview:chargeLabel];
    
    _mentionMoneyTextfield = [[UITextField alloc]initWithFrame:CGRectMake(90, 3, SCREEN_WIDTH - 100 , 50)];
    _mentionMoneyTextfield.placeholder = @"请输入提现金额";
    [_mentionMoneyTextfield setValue:[UIFont boldSystemFontOfSize:14.0f] forKeyPath:@"_placeholderLabel.font"];
    _mentionMoneyTextfield.keyboardType = UIKeyboardTypeDecimalPad;
    [chargeView addSubview:_mentionMoneyTextfield];
    
    
    _tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 60, SCREEN_WIDTH -20, 50)];
    _tipLabel.textColor = [UIColor hexStringToColor:RED_COLOR_VALUE];
    _tipLabel.numberOfLines = 2;
    if (_availableBalance)
    {
       _tipLabel.text = [NSString stringWithFormat:@"可提现金额：%@元\n(单笔提现金额应大于1元，小于50000元)",_availableBalance];
    }else
    {
      _tipLabel.text = @"可提现金额：0元\n(单笔提现金额应大于1元，小于50000元)";
    }
    
    _tipLabel.font = [UIFont systemFontOfSize:14];
    [backView addSubview:_tipLabel];
    
    //手机号码
    UIView * teleView = [[UIView alloc]initWithFrame:CGRectMake(0,110, SCREEN_WIDTH, 50)];
    teleView.backgroundColor = [UIColor whiteColor];
    [backView addSubview:teleView];
    
    UILabel * teleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, 50)];
    teleLabel.text = @"手机号码";
    [teleView addSubview:teleLabel];
    
    UILabel * telephone = [[UILabel alloc]initWithFrame:CGRectMake(90, 0, SCREEN_WIDTH - 100 , 50)];
    NSString * phoneNum = [[NSUserDefaults standardUserDefaults] objectForKey:@"mobile"];
    telephone.text = [self secureThePhoneNum:phoneNum];
    telephone.textColor = RGBA(194, 194, 200, 1);
    [teleView addSubview:telephone];
    
    _verifiCodeBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 100, 7.5f, 90, 35)];
    _verifiCodeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_verifiCodeBtn setTitle:@" 获取验证码 " forState:UIControlStateNormal];
    [_verifiCodeBtn setTitleColor:[UIColor hexStringToColor:RED_COLOR_VALUE] forState:UIControlStateNormal];
    _verifiCodeBtn.layer.cornerRadius = 2;
    _verifiCodeBtn.layer.masksToBounds = TRUE;
    _verifiCodeBtn.layer.borderWidth = 1;
    _verifiCodeBtn.layer.borderColor = [[UIColor hexStringToColor:RED_COLOR_VALUE]CGColor];
    [_verifiCodeBtn addTarget:self action:@selector(buttonGetTheCodeTapped:) forControlEvents:UIControlEventTouchUpInside];
    [teleView addSubview:_verifiCodeBtn];
    
    //验证码
    UIView * verifiCodeView = [[UIView alloc]initWithFrame:CGRectMake(0,170, SCREEN_WIDTH, 50)];
    verifiCodeView.backgroundColor = [UIColor whiteColor];
    [backView addSubview:verifiCodeView];
    
    UILabel * verifiLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, 50)];
    verifiLabel.text = @"验证码";
    [verifiCodeView addSubview:verifiLabel];
    
    _verifiCodeTextfield = [[UITextField alloc]initWithFrame:CGRectMake(90, 3, SCREEN_WIDTH - 100 , 50)];
    _verifiCodeTextfield.placeholder = @"请输入您收到的验证码";
    [_verifiCodeTextfield setValue:[UIFont boldSystemFontOfSize:14.0f] forKeyPath:@"_placeholderLabel.font"];
    _verifiCodeTextfield.keyboardType = UIKeyboardTypeNumberPad;

    [verifiCodeView addSubview:_verifiCodeTextfield];
    //提现按钮
    UIButton * mentionBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 240, SCREEN_WIDTH - 20, 35.0f*HSCALE)];
    mentionBtn.layer.cornerRadius = 5;
    mentionBtn.backgroundColor = [UIColor hexStringToColor:RED_COLOR_VALUE];
    [mentionBtn setTitle:@"提 现" forState:UIControlStateNormal];
    [mentionBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
    [mentionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [mentionBtn addTarget:self action:@selector(buttonMentionTapped:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:mentionBtn];

}
#pragma mark -------------获取验证码按钮方法
-(void)buttonGetTheCodeTapped:(id)sender
{
    
    UIButton * codeBtn  = (UIButton *)sender;
    codeBtn.enabled = FALSE;//点击后，让不可再点击
    
    [MBProgressHUD showHUDAddedTo:self.view animated:TRUE];

    [AppGlobalClass PostDataWithNSstring:REGIST_CODE withDictionary:@{@"mobileNumber":[[NSUserDefaults standardUserDefaults] objectForKey:@"mobile"]} success:^(NSDictionary *dictionary) {
        
        [codeBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        codeBtn.layer.borderColor = [[UIColor lightGrayColor]CGColor];
        if (!_timer)
        {
            _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeCounting) userInfo:nil repeats:TRUE];//开启定时器  倒计时结束后，在倒计时方法内使得按钮可以点击
            [_timer fire];
        }
        [MBProgressHUD hideHUDForView:self.view animated:TRUE];
 
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:TRUE];

        codeBtn.enabled = TRUE;
    } networkerror:^(NSString *networkerror) {
        codeBtn.enabled = TRUE;
        [MBProgressHUD hideHUDForView:self.view animated:TRUE];

    }];
}
#pragma mark--------------tableViewDelegateAndDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _bankArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellID = @"cellID";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
       
        UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5)];
        lineView.backgroundColor = RGBA(237, 239, 240, 1);
        [cell addSubview:lineView];

        if (indexPath.row == 0)
        {
            UILabel * tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 40, 70, 20)];
            tipLabel.text = @"提现到";
            tipLabel.tag = 99;
            [cell addSubview:tipLabel];
        }
        
        UIImageView * selectImageView = [[UIImageView alloc]initWithFrame:CGRectMake(80, 40, 20, 20)];
        selectImageView.tag = 10;
        [cell addSubview:selectImageView];
        
        UILabel *bankNameLab = [[UILabel alloc] initWithFrame:CGRectMake(120.0f, 25.0f, SCREEN_WIDTH-130.0f, 20.0f)];
        bankNameLab.font = [UIFont systemFontOfSize:17.0f];
        bankNameLab.textAlignment = NSTextAlignmentLeft;
        [bankNameLab setTag:100];
        [cell addSubview:bankNameLab];
        
        UILabel *cardNumLab = [[UILabel alloc] initWithFrame:CGRectMake(120.0f, bankNameLab.frame.origin.y+bankNameLab.frame.size.height+20.0f, SCREEN_WIDTH-130.0f, 20.0f)];
        cardNumLab.textAlignment = NSTextAlignmentLeft;
        cardNumLab.textColor = [UIColor grayColor];
        cardNumLab.font = [UIFont systemFontOfSize:14.0f];
        [cardNumLab setTag:101];
        [cell addSubview:cardNumLab];
    }
    CardManageModel *cardManageModel = [_bankArray objectAtIndex:indexPath.row];
    
    UILabel *modelBankNameLab = (UILabel *)[cell viewWithTag:100];
    modelBankNameLab.text = cardManageModel.bankName;
    
    UILabel *modelCardNumLab = (UILabel *)[cell viewWithTag:101];
    modelCardNumLab.text = [self secureTheBankNum:cardManageModel.accountNo];
    
    UIImageView * selectImageView = (UIImageView *)[cell viewWithTag:10];
    NSString * str = [NSString stringWithFormat:@"%@",indexPath];
    if ([[_selectDict objectForKey:str] isEqualToString:@"YES"])
    {
        selectImageView.image = [UIImage imageNamed:@"cc"];
    }else
    {
        selectImageView.image = [UIImage imageNamed:@"c"];
    }
    
    UILabel * tipLabel = (UILabel *)[cell viewWithTag:99];
    if (indexPath.row == 0)
    {
        tipLabel.hidden = FALSE;
    }
    else
    {
        tipLabel.hidden = TRUE;
    }
    
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    UIImageView * selectImageView = (UIImageView *)[cell viewWithTag:10];
    selectImageView.image = [UIImage imageNamed:@"cc"];
    _selectedCard = indexPath.row + 1;
    
    NSString * str = [NSString stringWithFormat:@"%@",indexPath];
    [_selectDict setObject:@"YES" forKey:str];//选中的按钮，对应设为YES
    
}
//取消上一次选择
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    UIImageView * selectImageView = (UIImageView *)[cell viewWithTag:10];
    selectImageView.image = [UIImage imageNamed:@"c"];
    NSString * str = [NSString stringWithFormat:@"%@",indexPath];
    [_selectDict removeObjectForKey:str];//取消的按钮，对应设为NO
}


#pragma mark-返回方法
-(void)buttonBackTapped:(id)sender
{
    [self.navigationController popViewControllerAnimated:TRUE];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSString *)secureThePhoneNum:(NSString *)phoneNum
{
    return [phoneNum stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
}
-(NSString *)secureTheBankNum:(NSString *)bankNum
{
          if (bankNum.length==19) {
            return [bankNum stringByReplacingCharactersInRange:NSMakeRange(3, bankNum.length-7) withString:@"************"];
        }
        else
        {
            return [bankNum stringByReplacingCharactersInRange:NSMakeRange(3, bankNum.length-7) withString:@"*********"];
        }
        
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:TRUE];
}
#pragma mark------上拉加载，下拉刷新
//刷新表
-(void)refreshTheProjectTableView
{
    _idx = 0;
    _n = 0;
    [self getHttpData];
}

//加载更多数据
- (void)AddtoTheProjectTableView
{
    [self getHttpData];
 }

//提现
- (void)buttonMentionTapped:(id)sender
{
    [self.view endEditing:TRUE];
    NSString * str = [[NSUserDefaults standardUserDefaults] objectForKey:@"payPasswordVStatus"];
    
    if(_selectedCard <= 0)
    {
        ALERT_VIEW(@"请选择提现的银行卡");
    }
    
    else if ([str intValue] == 0)
    {
        ALERT_VIEW(@"请先设置支付密码");
    }
    else if ([_mentionMoneyTextfield.text isEqualToString:@""])
    {
        ALERT_VIEW(@"请输入提现金额");
    }
    else if([_verifiCodeTextfield.text length] == 0)
    {
        ALERT_VIEW(@"请输入验证码");
    }
    else
    {
        if ([_mentionMoneyTextfield.text floatValue]<1.0)
        {
            ALERT_VIEW(@"单笔提现金额不能小于1元");
            return;
        }
        
        if ([_mentionMoneyTextfield.text floatValue] > [_availableBalance floatValue])
        {
            
            ALERT_VIEW(@"可提现金额不足");
            return;
        }
        if ([_mentionMoneyTextfield.text floatValue]>50000.0)
        {
            ALERT_VIEW(@"单笔提现金额不能超过5万元");
            return;
        }
       
        if (![self validateMoney:_mentionMoneyTextfield.text])
        {
            ALERT_VIEW(@"请输入合法的金额");
            return;
        }
        
        [MBProgressHUD showHUDAddedTo:self.view animated:TRUE];
        
        [AppGlobalClass PostDataWithNSstring:REGIST_ISRIGHT withDictionary:@{@"mobileNumber":[[NSUserDefaults standardUserDefaults] objectForKey:@"mobile"],@"checkCode":_verifiCodeTextfield.text} success:^(NSDictionary *dictionary) {
            if([[dictionary objectForKey:@"success"] isEqualToNumber:[NSNumber numberWithBool:TRUE]])
            {
                //验证码有效
                
                UIAlertView *inputPwdAlt = [[UIAlertView alloc] initWithTitle:nil message:@"请输入支付密码" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                inputPwdAlt.tag = 100;
                inputPwdAlt.alertViewStyle = UIAlertViewStyleSecureTextInput;
                [inputPwdAlt show];
            }
            else
            {
                //无效的话，进行弹框提示
                NSString * str = [dictionary objectForKey:@"message"];
                ALERT_VIEW(str);
            }
            [MBProgressHUD hideAllHUDsForView:self.view animated:TRUE];
            
        } failure:^(NSError *error) {
            [MBProgressHUD hideAllHUDsForView:self.view animated:TRUE];
            
        } networkerror:^(NSString *networkerror) {
            [MBProgressHUD hideAllHUDsForView:self.view animated:TRUE];
        }];

        
       
        
    }
}
//金额验证
-(BOOL)validateMoney:(NSString *)money
{
    NSString *phoneRegex = @"^[0-9]+(\\.[0-9]{1,2})?$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:money];
}
//
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
